<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>yukari world</title>
<#include "/lib/base_source.ftl">
<style type="text/css">
</style>
</head>
<body>
<div class='whole-container'>
<#include "/lib/header.ftl">
    <div>
        <ul class="breadcrumb">
        	<li>贡品管理</li><span class="divider">/</span>
            <li>任务列表</li>
        </ul>
    </div>
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="container span12">
            <#include "/lib/alert.ftl">

                <div class='main-content'>
                    <div class="well form-inline">
                        <div class='main-action'>
                            <form id="searchForm" style="display: inline">
                                <input name="size" value="${pager.size}" id="size" type="hidden">
                                <input name="page" value="${pager.page}" id="page" type="hidden">
                                <select name="status" id="status" onchange="searchStatus()">
                                    <option value="">全部</option>
                                    <option value="0" <#if status == 0>selected</#if>>未领取</option>
                                    <option value="1" <#if status == 1>selected</#if>>已领取</option>
                                    <option value="2" <#if status == 2>selected</#if>>已完成</option>
                                    <option value="-1" <#if status == -1>selected</#if>>已废弃</option>
                                </select>
                            </form>



							<a href="${rc.contextPath}/admin/cosmetics/add" class="btn btn-sm btn-info" >添加任务</a>
                        </div>
                    </div>

                    <div class="table-content">
                    <#-- table -->
                        <table class="table table-striped table-bordered table-condensed" id="itemTable" style="font-size:12px;word-break:break-all;word-wrap:break-word;">
                            <thead>
                            <tr >
                                <th style="width: 5%">编号</th>
                                <th style="width: 10%">品牌</th>
                                <th style="width: 20%">名字</th>
                                <th style="width: 20%">图片(点击放大)</th>
                                <th style="width: 5%">价格</th>
                                <th style="width: 10%">地址</th>
                                <th style="width: 10%">备注</th>
                                <th style="width: 13%">状态</th>
                                <th style="width: 7%">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <#if list??>
                            <#list list as item>
                            	<tr>
                                	<td>${item.id}</td>
                                	<td>${item.brand}</td>
                                	<td>${item.name}</td>
                                	<td><#if item.image != ''><a href="http://image.loveyukari.com/${item.image}"  target="_blank" ><img src="http://image.loveyukari.com/${item.image}" style="width: 100%" /></a></#if></td>
                                	<td>${item.price}</td>
                                	<td>${item.address}</td>
                                	<td>${item.note}</td>
                                	<td>
										<#if item.status == 0>
										    未领取
										<#elseif item.status == 1>
											已领取, 领取人是: ${item.account}
										<#elseif item.status == 2>
                                            已完成, 领取人是: ${item.account}
                                        <#elseif item.status == -1>
                                            已废弃<#if item.account != ''>, 领取人是: ${item.account}</#if>
										</#if>
									</td>
									<td>
										<#if item.status == 0>
                                            <a class="btn btn-sm btn-primary" href="javascript:updateDetail('${item.id}')" >修改任务</a>
                                            <a class="btn btn-sm btn-primary" href="javascript:updateAccount('${item.id}')" >领取任务</a>
                                            <a class="btn btn-sm btn-danger" href="javascript:updateClose('${item.id}')" >关闭任务</a>
										<#elseif item.status == 1>
                                            <a class="btn btn-sm btn-info" href="javascript:updateAccount('${item.id}')" >修改领取人</a>
                                            <a class="btn btn-sm btn-primary" href="javascript:updateSuccess('${item.id}')" >完成任务</a>
                                            <a class="btn btn-sm btn-danger" href="javascript:updateClose('${item.id}')" >关闭任务</a>
										</#if>
									</td>
                                </tr>
                            </#list>
                            </#if>
                            </tbody>
                        </table>

                        <input name="total" value="${pager.total}" id="total" type="hidden">
                        <div class="pagination" id="itemPage"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>

    $(document).ready(function(){
		$.manage.pageList(".pagination","#searchForm","#page","#total","#size");
    });
	    

    function searchStatus() {
        var status = $("#status").val();
        location.href = "${rc.contextPath}/admin/cosmetics/list?status="+status;
    }

	function updateAccount(id){
	    var account = prompt("请输入领取人");
	    if (account){
            $.ajax({
                'url' : "${rc.contextPath}/admin/cosmetics/updateAccount",
                'dataType' : "json",
                'data' :  {"id":id,"account":account},
                'type':'post',
                'success':function(json){
                    if(json.code == 0){
                        location.reload();
                    }else{
                        alert(json.message);
                    }
                }
            });
        }
	}

	function updateClose(id){
        $.ajax({
            'url' : "${rc.contextPath}/admin/cosmetics/close",
            'dataType' : "json",
            'data' :  {"id":id},
            'type':'post',
            'success':function(json){
                if(json.code == 0){
                    location.reload();
                }else{
                    alert(json.message);
                }
            }
        });
	}


    function updateSuccess(id){
        $.ajax({
            'url' : "${rc.contextPath}/admin/cosmetics/updateSuccess",
            'dataType' : "json",
            'data' :  {"id":id},
            'type':'post',
            'success':function(json){
                if(json.code == 0){
                    location.reload();
                }else{
                    alert(json.message);
                }
            }
        });
    }

    function updateDetail(id){
        location.href = "${rc.contextPath}/admin/cosmetics/update?id="+id;
    }


</script>
</body>
</html>